home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
othergnu
/
ispell.zoo
/
ispell.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-04-19
|
27KB
|
1,370 lines
/* -*- Mode:Text -*- */
#define MAIN
/*
* ispell.c - An interactive spelling corrector.
*
* Copyright (c), 1983, by Pace Willisson
* Permission for non-profit use is hereby granted.
* All other rights reserved.
*
* 1987, Robert McQueer, added:
* -w option & handling of extra legal word characters
* -d option for alternate dictionary file
* -p option & WORDLIST variable for alternate personal dictionary
* -x option to suppress .bak files.
* 8 bit text & config.h parameters
* 1987, Geoff Kuenning, added:
* -c option for creating suffix suggestions from raw words
* suffixes in personal dictionary file
* hashed personal dictionary file
* -S option for unsorted word lists
* 1987, Greg Schaffer, added:
* -T option (for TeX and LaTeX instead of troff) [later changed to -t]
* passes over \ till next whitespace.
* does not recognize % (comment)
*/
#include <stdio.h>
#include <ctype.h>
#include <sys/param.h>
#if defined(USG) || defined(atarist)
#include <sys/types.h>
#endif
#include <sys/stat.h>
#include "config.h"
#include "ispell.h"
#include "version.h"
#define ISTEXTERM(c) (((c) == '{') || \
((c) == '}') || \
((c) == '[') || \
((c) == ']'))
FILE *infile;
FILE *outfile;
char hashname[MAXPATHLEN];
extern struct dent *treeinsert();
extern char *upcase ();
extern char *lowcase ();
extern char *rindex();
extern char *strcpy ();
/*
** we use extended character set range specifically to allow intl.
** character set characters. We are being REALLY paranoid about indexing
** this array - explicitly cast into unsigned INTEGER, then mask
** If NO8BIT is set, text will be masked to ascii range.
*/
static int Trynum;
#ifdef NO8BIT
static char Try[128];
static char Checkch[128];
#define iswordch(X) (Checkch[((unsigned)(X))&0x7f])
#else
static char Try[256];
static char Checkch[256];
#define iswordch(X) (Checkch[((unsigned)(X))&0xff])
#endif
static int sortit = 1;
givehelp ()
{
erase ();
printf ("Whenever a word is found that is not in the dictionary,\r\n");
printf ("it is printed on the first line of the screen. If the dictionary\r\n");
printf ("contains any similar words, they are listed with a single digit\r\n");
printf ("next to each one. You have the option of replacing the word\r\n");
printf ("completely, or choosing one of the suggested words.\r\n");
printf ("\r\n");
printf ("Commands are:\r\n\r\n");
printf ("R Replace the misspelled word completely.\r\n");
printf ("Space Accept the word this time only\r\n");
printf ("A Accept the word for the rest of this file.\r\n");
printf ("I Accept the word, and put it in your private dictionary.\r\n");
printf ("0-9 Replace with one of the suggested words.\r\n");
printf ("L Look up words in system dictionary.\r\n");
printf ("Q Write the rest of this file, ignoring misspellings, ");
printf ( "and start next file.\r\n");
printf ("X Exit immediately. Asks for confirmation. ");
printf ( "Leaves file unchanged.\r\n");
printf ("! Shell escape.\r\n");
printf ("^L Redraw screen.\r\n");
printf ("\r\n\r\n");
printf ("-- Type space to continue --");
fflush (stdout);
while (getchar () != ' ')
;
}
char *getline();
int cflag = 0;
int lflag = 0;
int incfileflag = 0;
int aflag = 0;
int fflag = 0;
#if !defined(USG) && !defined(atarist)
int sflag = 0;
#endif
int xflag = 0;
int tflag = 0;
char *askfilename;
static char *Cmd;
usage ()
{
fprintf (stderr,
"Usage: %s [-dfile | -pfile | -wchars | -t | -x | -S] file .....\n",
Cmd);
fprintf (stderr,
" %s [-dfile | -pfile | -wchars | -t] -l\n",
Cmd);
#if !defined(USG) && !defined(atarist)
fprintf (stderr,
" %s [-dfile | -pfile | -ffile | -t | -s] {-a | -A}\n",
Cmd);
#else
fprintf (stderr,
" %s [-dfile | -pfile | -ffile | -t] {-a | -A}\n",
Cmd);
#endif
fprintf (stderr, " %s [-wchars] -c\n", Cmd);
fprintf (stderr, " %s -v\n", Cmd);
exit (1);
}
static initckch()
{
register int c;
Trynum = 0;
#ifdef NO8BIT
for (c = 0; c < 128; ++c) {
#else
for (c = 0; c < 256; ++c) {
#endif
if (myalpha((char) c)) {
Checkch[c] = (char) 1;
if (myupper((char) c)) {
Try[Trynum] = (char) c;
++Trynum;
}
}
else
Checkch[c] = (char) 0;
}
}
main (argc, argv)
char **argv;
{
char *p;
char *cpd;
char num[4];
unsigned mask;
static char outbuf[BUFSIZ];
extern char *getenv();
Cmd = *argv;
initckch();
#ifdef atarist
if((p = getenv("LIB")) != NULL)
sprintf(hashname,"%s/%s",p,DEFHASH);
else
#endif
sprintf(hashname,"%s/%s",LIBDIR,DEFHASH);
cpd = NULL;
argv++;
argc--;
while (argc && **argv == '-') {
switch ((*argv)[1]) {
case 'v':
printf ("%s\n", Version_ID);
exit (0);
case 't':
tflag++;
break;
case 'A':
incfileflag = 1;
aflag = 1;
break;
case 'a':
aflag++;
break;
case 'c':
cflag++;
lflag++;
break;
case 'x':
xflag++;
break;
case 'f':
fflag++;
p = (*argv)+2;
if (*p == '\0') {
argv++; argc--;
if (argc == 0)
usage ();
p = *argv;
}
askfilename = p;
break;
case 'l':
lflag++;
break;
#if !defined(USG) && !defined(atarist)
case 's':
sflag++;
break;
#endif
case 'S':
sortit = 0;
break;
case 'p':
cpd = (*argv)+2;
if (*cpd == '\0') {
argv++; argc--;
if (argc == 0)
usage ();
cpd = *argv;
}
break;
case 'd':
p = (*argv)+2;
if (*p == '\0') {
argv++; argc--;
if (argc == 0)
usage ();
p = *argv;
}
if (*p == '/')
strcpy(hashname,p);
else
sprintf(hashname,"%s/%s",LIBDIR,p);
break;
case 'w':
num[3] = '\0';
#ifdef NO8BIT
mask = 0x7f;
#else
mask = 0xff;
#endif
p = (*argv)+2;
if (*p == '\0') {
argv++; argc--;
if (argc == 0)
usage ();
p = *argv;
}
while (Trynum <= mask && *p != '\0') {
if (*p != 'n' && *p != '\\') {
Checkch[((unsigned)(*p))&mask] = (char) 1;
Try[Trynum] = *p & mask;
++p;
}
else {
++p;
num[0] = '\0';
num[1] = '\0';
num[2] = '\0';
num[3] = '\0';
if (isdigit (p[0]))
num[0] = p[0];
if (isdigit (p[1]))
num[1] = p[1];
if (isdigit (p[2]))
num[2] = p[2];
if (p[-1] == 'n') {
p += strlen (num);
num[0] = atoi (num);
}
else {
p += strlen (num);
if (num[0])
num[0] -= '0';
if (num[1]) {
num[0] <<= 3;
num[0] += num[1] - '0';
}
if (num[2]) {
num[0] <<= 3;
num[0] += num[2] - '0';
}
}
Try[Trynum] = num[0] & mask;
Checkch[num[0] & mask] = 1;
}
++Trynum;
}
break;
default:
usage();
}
argv++; argc--;
}
if (!argc && !lflag && !aflag)
usage ();
if (linit () < 0)
exit (0);
treeinit (cpd);
if (aflag) {
askmode ();
exit (0);
}
setbuf (stdout, outbuf);
if (lflag) {
infile = stdin;
checkfile ();
exit (0);
}
terminit ();
while (argc--)
dofile (*argv++);
done ();
}
char firstbuf[BUFSIZ], secondbuf[BUFSIZ];
char *currentchar;
char token[BUFSIZ];
int quit;
char *currentfile = NULL;
dofile (filename)
char *filename;
{
int c;
char bakfile[256];
struct stat statbuf;
char *cp;
currentfile = filename;
if ((infile = fopen (filename, "r")) == NULL) {
fprintf (stderr, "Can't open %s\r\n", filename);
sleep (2);
return;
}
if (access (filename, 2) < 0) {
fprintf (stderr, "Can't write to %s\r\n", filename);
sleep (2);
return;
}
fstat (fileno (infile), &statbuf);
#ifdef atarist
{
char *p, c;
extern char *getenv();
if((p = getenv("TEMP")) != NULL)
{
strcpy(tempfile, p);
c = p[(strlen(p) - 1)];
if((c != '/') || (c != '\\'))
strcat(tempfile,"/");
}
}
#endif
strcpy(tempfile, TEMPNAME);
mktemp (tempfile);
chmod (tempfile, statbuf.st_mode);
if ((outfile = fopen (tempfile, "w")) == NULL) {
fprintf (stderr, "Can't create %s\r\n", tempfile);
sleep (2);
return;
}
quit = 0;
/* See if the file is a .tex file. If so, set the appropriate flag. */
if ((cp = rindex (filename, '.')) != NULL && strcmp (cp, ".tex") == 0)
tflag = 1;
checkfile